package com.youfan.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.youfan.entity.Wuliu;
import com.youfan.page.CommonPage;
import com.youfan.utils.HttpClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 友凡机器人
 */
@Service
@Slf4j
public class YoufanWuliuServiceImpl {

    public CommonPage<Wuliu> queryByOrderId(String orderid) {
        String result = HttpClient.doGet("http://127.0.0.1:8001/list?orderid="+orderid);
        System.out.println(result);
        JSONObject jsonObject = JSONObject.parseObject(result);
        JSONArray jsonArray =  jsonObject.getJSONObject("data").getJSONArray("wuliuinf");
        List<Wuliu> resultList = new ArrayList<Wuliu>();
        for(int i=0;i<jsonArray.size();i++){
            Wuliu wuliu = new Wuliu();
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            String id = jsonObject1.getString("Id");
            String orderId = jsonObject1.getString("OrderId");
            String processInfo = jsonObject1.getString("ProcessInfo");
            String timeInfo = jsonObject1.getString("TimeInfo");
            wuliu.setId(id);
            wuliu.setOrderId(orderId);
            wuliu.setProcessInfo(processInfo);
            wuliu.setTimeInfo(timeInfo);
            resultList.add(wuliu);
        }


        return CommonPage.restPage( resultList);
    }

}
